package org.example;

import cn.hutool.core.convert.Convert;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import org.junit.Test;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author: HAPPY
 * @Project_name: JSF
 * @Package_name: org.example
 * @Date: 2021/11/22 17:25
 * @Description:
 */
public class InitCourseData {
    public int getInDayNo(String no) {
        switch (no) {
            case "1-2":
                return 0;
            case "3-4":
                return 1;
            case "5-6":
                return 2;
            case "7-8":
                return 3;
            case "9-10":
                return 4;
        }
        return 0;
    }

    public int getNo(String time) {
        int dayNo = 0;
        int inDayNo = 0;
        switch (time.substring(0, 3)) {
            case "星期一":
                dayNo = 1;
                break;
            case "星期二":
                dayNo = 2;
                break;
            case "星期三":
                dayNo = 3;
                break;
            case "星期四":
                dayNo = 4;
                break;
            case "星期五":
                dayNo = 5;
                break;
            case "星期六":
                dayNo = 6;
                break;
            case "星期日":
                dayNo = 7;
                break;
        }
        inDayNo = getInDayNo(time.substring(4));
        int res = (dayNo - 1) * 5 + inDayNo;
        return res;
    }

    @Test
    public void test001() {
        System.out.println(getNo("星期一1-3"));
    }
    @Test
    public void initNo() {
        try {
            List<Entity> entityList = Db.use().query("select * from stu_select_crouse.course");
            for (Entity entity : entityList) {
                Db.use().update(
                        Entity.create().set("no", getNo((String) entity.get("time"))), //修改的数据
                        Entity.create("course").set("id", entity.get("id")) //where条件
                );
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void initCategory() {

        try {
            List<Entity> entityList = Db.use().query("select * from stu_select_crouse.course");

            for (Entity entity : entityList) {

                String id = (String) entity.get("id");
                int idd = Convert.toInt(id.substring(0, 3));
                String cate = idd == 882 ? "人文社会科学类课程" : "艺术类课程";
                Db.use().update(
                        Entity.create().set("category", cate), //修改的数据
                        Entity.create("course").set("id", entity.get("id")) //where条件
                );
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void deleteNBSP() {
        try {
            List<Entity> courseList = Db.use().query("select * from course");
            for (Entity entity : courseList) {
                String teacher = entity.getStr("teacher");
                Db.use().update(
                        Entity.create().set("teacher", teacher.replaceAll(" ", ""))
                                .set("teacher", teacher.replaceAll("()", "")), //修改的数据
                        Entity.create("course").set("id", entity.get("id")) //where条件
                );
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
